/*
 * Author: vyouzhi <vyouzhi@163.com>
 * http://www.xda.cn
 *
 * File: record_lib.c
 * Create Date: 2011-07-13 11:27:54
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "store_lib.h"
#include "conf_lib.h"
#include "mysql_lib.h"
#include "time_lib.h"

long dostore(const char *sub){
	int is_store = 0;
	long lastid;
	char *sql, *sqlescape, *logdb;
	/*char usedb[100], lgn[100], ctable[200];*/
	SQL_CONN *sm_conn;

	is_store = atoi(conf_get("store"));
	
	if(0 == is_store){return (0);}

	logdb = conf_get("log_db");

	/*sprintf(lgn, "sql_log_%s", ln);*/

	sm_conn = connect_sql();
	/*sprintf(usedb, "use %s;", logdb);

	pthread_mutex_lock(&sm_conn->lock);
	*/
	sqlescape = escape_mysql(sub, sm_conn->myconn);
	sql = (char *)calloc(strlen(sqlescape)+500, sizeof(char));

	sprintf(sql, "INSERT INTO `%s`.`sql_log` (`sql`)VALUES ('%s');", logdb,  sqlescape);	
	
	lastid = set_mysql(sql, sm_conn);

	free(sql);
	free(sqlescape);

	return lastid;
}

/* vim: set ts=4 sw=4: */
